package com.builder.settings;

import com.builder.settings.interfaces.PropertiesStorage;
import com.gooddies.utils.IteratorToIterable;
import com.gooddies.utils.KeyValue;
import java.util.ArrayList;
import java.util.List;

public class ListPropertyStorage extends PropertiesStorage {

    private final List<KeyValue<String, String>> values = new ArrayList<>();

    public ListPropertyStorage() {
    }

    public ListPropertyStorage(List<KeyValue<String, String>> values) {
        for (KeyValue<String, String> v : values) {
            this.values.add(v);
        }
    }

    public ListPropertyStorage add(String key, String value) {
        values.add(new KeyValue<String, String>(key, value));
        return this;
    }

    @Override
    public Iterable<KeyValue<String, String>> getProperties() {
        return IteratorToIterable.once(values.iterator());
    }

    @Override
    public void setProperties(Iterable<KeyValue<String, String>> values) {
        this.values.clear();
        for(KeyValue<String, String>v:values){
            this.values.add(v);
        }
    }
    
    
}
